package zhoug.zui.date;

/**
 * 日期时间工具
 *
 * @Author 35574
 * @Date 2021/4/13
 * @Description
 */
class DateTimeUtils {

    /**
     * 获取显示的year的集合
     *
     * @param minYear 最小值 默认 1900
     * @param maxYear 最大值 默认 2200
     * @return
     */
    public static String[] getDisplayYears(int minYear, int maxYear,String suffix) {
        if (minYear <= 0) {
            minYear = 1900;
        }
        if (maxYear <= 0) {
            maxYear = 2200;
        }
        int count = maxYear - minYear + 1;
        String[] years = new String[count];
        for (int i = 0; i < count; i++) {
            if(suffix!=null){
                years[i] =(minYear + i)+suffix;
            }else{
                years[i] = String.valueOf(minYear + i);
            }
        }
        return years;
    }

    /**
     * 获取显示的year的集合
     *
     * @param minYear 最小值 默认 1900
     * @param maxYear 最大值 默认 2200
     * @return
     */
    public static String[] getDisplayYears(int minYear, int maxYear) {
      return getDisplayYears(minYear,maxYear,null);
    }

    /**
     * 获取显示的月份集合
     *
     * @param minMonth 最小值 默认值:1
     * @param maxMonth 最大值 默认值:12
     * @return
     */
    public static String[] getDisplayMonths(int minMonth, int maxMonth,String suffix) {
        if (minMonth <= 0) {
            minMonth = 1;
        }
        if (maxMonth <= 0) {
            maxMonth = 12;
        }

        int count = maxMonth - minMonth + 1;
        String[] months = new String[count];
        for (int i = 0; i < count; i++) {
            String s = String.valueOf(minMonth + i);
            if(s.length()==1){
                s="0"+s;
            }
            if(suffix!=null){
                months[i] =s+suffix;
            }else{
                months[i] =s;
            }
        }
        return months;
    }

    /**
     * 获取显示的月份集合
     *
     * @param minMonth 最小值 默认值:1
     * @param maxMonth 最大值 默认值:12
     * @return
     */
    public static String[] getDisplayMonths(int minMonth, int maxMonth) {
      return getDisplayMonths(minMonth,maxMonth,null);
    }

    /**
     * 获取显示的天集合
     *
     * @param year   年
     * @param month  月
     * @param minDay 最小值
     * @param maxDay 最大值
     * @return
     */
    public static String[] getDisplayDays(int year, int month, int minDay, int maxDay,String suffix) {
        int maxDayOfMonth = 0;//本月的最大天数
        if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
            maxDayOfMonth = 31;
        } else if (month == 2) {
            maxDayOfMonth = year % 4 == 0 ? 29 : 28;
        } else {
            maxDayOfMonth = 30;
        }
        if (minDay <= 0) {
            minDay = 1;
        }
        if (maxDay > maxDayOfMonth || maxDay <= 0) {
            maxDay = maxDayOfMonth;
        }
        int count = maxDay - minDay + 1;
        String[] days = new String[count];
        for (int i = 0; i < count; i++) {
            String s = String.valueOf(minDay + i);
            if(s.length()==1){
                s="0"+s;
            }
            if(suffix!=null){
                days[i] =s+suffix;
            }else{
                days[i] =s;
            }
        }
        return days;
    }

    /**
     * 获取显示的天集合
     *
     * @param year   年
     * @param month  月
     * @param minDay 最小值
     * @param maxDay 最大值
     * @return
     */
    public static String[] getDisplayDays(int year, int month, int minDay, int maxDay ) {
        return getDisplayDays(year,month,minDay,maxDay,null);
    }

    public static String[] getDisplayHours(int minHour, int maxHour,String suffix) {
        if (minHour < 0) {
            minHour = 0;
        }
        if (maxHour < 0) {
            minHour = 23;
        }
        int count = maxHour - minHour + 1;
        String[] hours = new String[count];
        for (int i = 0; i < count; i++) {
            String s = String.valueOf(minHour + i);
            if(s.length()==1){
                s="0"+s;
            }
            if(suffix!=null){
                hours[i] =s+suffix;
            }else{
                hours[i] =s;
            }

        }
        return hours;
    }

    public static String[] getDisplayHours(int minHour, int maxHour) {
        return getDisplayHours(minHour,maxHour,null);
    }

    public static String[] getDisplayMinutes(int minMinute, int maxMinute,String suffix) {
        if (minMinute < 0) {
            minMinute = 0;
        }
        if (maxMinute < 0) {
            maxMinute = 59;
        }
        int count = maxMinute - minMinute + 1;
        String[] minutes = new String[count];
        for (int i = 0; i < count; i++) {
            String s = String.valueOf(minMinute + i);
            if(s.length()==1){
                s="0"+s;
            }
            if(suffix!=null){
                minutes[i] =s+suffix;
            }else{
                minutes[i] =s;
            }

        }
        return minutes;
    }

    public static String[] getDisplayMinutes(int minMinute, int maxMinute) {
        return getDisplayMinutes(minMinute,maxMinute,null);
    }

}
